// 封装cookie对应的方法 常用的对应的key和value expires过期时间  path
//set的方法
export function setCookie(key, value, date, path) {
    if (date instanceof Date) { // instanceof是否俩个属于同一个类型
        document.cookie = `${encodeURIComponent(key)}=${encodeURIComponent(value)};expires=${date};path=${path}`
    } else {
        document.cookie = `${encodeURIComponent(key)}=${encodeURIComponent(value)};expires=${new Date()};path=${path}`
    }
}
// get的方法 获取对应key的cookie值
// username=zhangsan;age=lisi
export function getCookie(key) {
    var key = encodeURIComponent(key)
    var cookies = document.cookie.split(';')
    for (var i in cookies) {
        //取出对应的键的下标
        var index = cookies[i].indexOf('=')
        if (cookies[i].indexOf(key) != -1) {
            var value = cookies[i].substring(index + 1)
            return decodeURIComponent(value)
        }
    }
    return ''
}
//remove 间隔几天以后过期
export function removeCookie(key, day) {
    var date = new Date()
    date.setDate(date.getDate + day)
    document.cookie = encodeURIComponent(key) + '=;expires=' + date
}